package com.mediacloud.app.newsmodule.fragment.newslist;

import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.mediacloud.app.assembly.adapter.IAdapterTitle;
import com.mediacloud.app.assembly.util.BitmapUtil;
import com.mediacloud.app.assembly.util.Utility;
import com.mediacloud.app.assembly.views.CircularImageViewX;
import com.mediacloud.app.assembly.views.ImageButtonX;
import com.mediacloud.app.assembly.views.NetImageView;
import com.mediacloud.app.assembly.views.NetImageViewOld.ImgLoadingComplete;
import com.mediacloud.app.assembly.views.RadioButtonX;
import com.mediacloud.app.model.fragment.INaviateState;
import com.mediacloud.app.model.news.CatalogItem;
import com.mediacloud.app.model.utils.AppModuleUtils;
import com.mediacloud.app.nav2.interfaces.ISecondFragment;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.fragment.navigate.IHammerNavigate4LBS;
import com.mediacloud.app.newsmodule.utils.LBSChooseListener;
import com.mediacloud.app.newsmodule.utils.LoginUtils;
import com.mediacloud.app.reslib.broadcast.GeneralBroadcast;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig.AppLayoutStyle;
import com.mediacloud.app.reslib.util.HomePageEntrance;
import com.mediacloud.app.user.broad.LoginBroadcast;
import com.mediacloud.app.user.broad.LoginBroadcast.UserInfoChanged;
import com.mediacloud.app.user.model.IUserInfo;
import com.mediacloud.app.user.model.UserInfo;
import com.mediacloud.app.xnav.EditColumnViewX;
import com.mediacloud.app.xnav.NavToolKt;

import java.util.ArrayList;
import java.util.List;

/**
 * 顶部带栏目结构的fragment
 */
public class TableCatalogItemsFragment extends TableCatalogItemsFragmentBase<CatalogItem> implements UserInfoChanged, OnClickListener, EditColumnViewX.OnChangeListener, EditColumnViewX.OnChannelSelectLisener, ISecondFragment {
    protected ImageButtonX menuBtnTab;
    protected View menuBtnContainer;
    CircularImageViewX userIcon;
    LoginBroadcast loginBroadcast;
    NetImageView skinHeaderBgImage;
    EditColumnViewX mEditColumnView;
    RelativeLayout mShowEdit;
    protected List<CatalogItem> mShowMenuData;
    ImageView expand_Btn;
    View loadingLayout;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initLoginBroad();
    }

    protected void initLoginBroad() {
        loginBroadcast = new LoginBroadcast();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(LoginBroadcast.SignIn);
        intentFilter.addAction(LoginBroadcast.SignOut);
        getActivity().registerReceiver(loginBroadcast, intentFilter);
        loginBroadcast.userInfoChanged = this;
    }

    boolean openNavigateEdit;


    @Override
    protected void initTableView() {
        super.initTableView();

        mEditColumnView = findViewById(R.id.editcolumnview);
        if (mNavigate != null)
            mEditColumnView.setCataLogId(mNavigate.getId());
        NavToolKt.initData(mEditColumnView, navigateItems);
        NavToolKt.setAdapters(mEditColumnView);
        new Thread() {
            @Override
            public void run() {
                NavToolKt.saveChannel(mEditColumnView);
            }
        }.start();

        mEditColumnView.setOnChangeListener(this);
        mEditColumnView.setOnChannelSelectLisener(this);
        mShowEdit = findViewById(R.id.expand_container_taps);
        loadingLayout = findViewById(R.id.loadingLayout);
        openNavigateEdit = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getOtherFunction() != null && AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getOtherFunction().getNavigate_edit() > 0;//"1".equals(getActivity().getResources().getString(R.string.openNavigateEdit));
        if (!openNavigateEdit)
            mShowEdit.setVisibility(View.GONE);
        else {
            mShowEdit.setVisibility(View.VISIBLE);
            mShowEdit.setOnClickListener(this);
            boolean isAddMarkStyle = "1".equals(getActivity().getResources().getString(R.string.navigate_editi_iconstyle));
            expand_Btn = Utility.findViewById(mRootView, R.id.expand_Btn);
            if (isAddMarkStyle) {
                expand_Btn.setImageResource(R.drawable.new_expand_ico);
            }
        }
    }

    @Override
    public void initView() {
        skinHeaderBgImage = Utility.findViewById(mRootView, R.id.skinHeaderBgImage);
        userIcon = Utility.findViewById(mRootView, R.id.userIcon);
        if (userIcon != null) {
            userIcon.checkFilesuffix = false;
            userIcon.defaultBackGroundColor = Color.TRANSPARENT;
            userIcon.defaultRes = R.drawable.new_user_logo_login;
            userIcon.completeListener = new ImgLoadingComplete() {

                @Override
                public void onComplete() {
                    userIcon.setScaleType(ScaleType.FIT_XY);
                }

                @Override
                public void loadFailed() {

                }
            };
        }
        menuBtnTab = Utility.findViewById(mRootView, R.id.menuBtnTab);
        menuBtnContainer = Utility.findViewById(mRootView, R.id.menuBtnContainerappfac);
        if (menuBtnContainer != null)
            menuBtnContainer.setVisibility(View.GONE);
        mContentViewPager = Utility.findViewById(mRootView, R.id.mContentViewPager);
        mCatalogItemContainer = mRootView.findViewById(R.id.mCatalogItemContainer);
//        mCatalogGroupContainer = mRootView.findViewById(R.id.mCatalogGroupContainer);
        topContainer = mRootView.findViewById(R.id.topContainer);
        getArgs();
        setListener();
        setTopCatalogElementChilds();
        mRootView.postDelayed(new Runnable() {
            @Override
            public void run() {

                initTableView();
                setTabLayoutData();
                loadingLayout.setVisibility(View.GONE);
            }
        }, 500);
       /* initTableView();
        setTabLayoutData();
        loadingLayout.setVisibility(View.GONE);*/
    }

    List<Fragment> list = new ArrayList<>();

    @Override
    public void onPageSelected(int index) {
//        super.onPageSelected(index);
        choosedIndexNavigate(index);
    }

    @Override
    protected void setTabLayoutData() {
//        super.setTabLayoutData();
        List<CatalogItem> data = mEditColumnView.getShowData();
        mShowMenuData = new ArrayList<>();
        mShowMenuData.addAll(data);
        for (int i = 0; mShowMenuData != null && i < mShowMenuData.size(); i++) {
            //加按钮对应的fragment
            Fragment fragment = getViewContentFragment(mShowMenuData.get(i));
            if (fragment != null) {
                list.add(fragment);
            }
        }
        try {
            if (list.size() > 0) {
                //如果子项只有一个table  那就把上面的tableNavigate隐藏掉
                setCatalogItemContentList(getChildFragmentManager(), list);
                List<IAdapterTitle> titleList = new ArrayList<>();
                titleList.addAll(mShowMenuData);
                contentFragmentAdapter.titleList = titleList;
               // AppThemeTabLayoutStyle.setTabLayoutStyle(getActivity(), mCatalogItemContainer);
                mCatalogItemContainer.setViewPager(mContentViewPager);
            }
        } catch (Exception e) {
            if (e != null) {
                e.printStackTrace();
                Log.e(TAG, e.getMessage() + "");
            }
        }
    }

    /**
     * 根据栏目列表长度  创建相应个数的子fragment
     */
   /* public void createRadioButtonItems() {
        mShowMenuData = new ArrayList<>();
        List<CatalogItem> data = mEditColumnView.getShowData();
        mShowMenuData.addAll(data);
        for (int i = 0; mShowMenuData != null && i < mShowMenuData.size(); i++) {
            final int index = i;
            //加按钮
            final RadioButtonX radioButtonX = createRadioButtonItem(mShowMenuData.get(i));
            RadioGroup.LayoutParams lp = getItemRadioButtonLayoutParams();
            */

    /**
     * app台的二级导航字体和底部table字体就用系统默认的字体
     **//*
            String currentTenantid = getResources().getString(R.string.tenantid);
            if (currentTenantid.equals(getResources().getString(R.string.tenant_jiangxi))) {
                if (AppDoSomething.doSomething.getJianxiTitleFont() != null) {
                    radioButtonX.setTypeface(AppDoSomething.doSomething.getJianxiTitleFont());
                }
                radioButtonX.setTextSize(18);
                radioButtonX.uncheckedTextColor = 0xFF262626;
            } else {
                radioButtonX.setTextSize(TypedValue.COMPLEX_UNIT_PX, appfactory_topcatalog_unchecked_textsize);
            }
            radioButtonX.setOnCheckedChangeListener(getRadioButtonCheckeChangedListener(radioButtonX, index));
            radioButtonX.updateEffDrawable();
            int space = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_spacing();
            if (space > 0)
            {
                if(Utility.isAdMachine(getActivity()))
                    lp.setMarginEnd(space);
                else
                    lp.setMarginEnd(Utility.dpToPx(getActivity(), space / 3.0f));
            }else{
                int margin = getResources().getDimensionPixelSize(R.dimen.appfactory_topcatalog_btnmargin);
                lp.setMarginEnd(margin);
            }
            if(i==0){
                lp.setMarginStart(getResources().getDimensionPixelSize(R.dimen.topcatalog_item_marginStart));
            }
            mCatalogGroupContainer.addView(radioButtonX, lp);
            //加按钮对应的fragment
            Fragment fragment = getViewContentFragment(mShowMenuData.get(i));
            if (fragment != null) {
                list.add(fragment);
            }
        }
        try {
            if (list.size() > 0) {
                RadioButton radioButton = ((RadioButton) mCatalogGroupContainer.getChildAt(0));
                radioButton.setChecked(true);
                //如果子项只有一个table  那就把上面的tableNavigate隐藏掉
                setCatalogItemContentList(getChildFragmentManager(), list);
            }
        } catch (Exception e) {
            if(e!=null) {
                e.printStackTrace();
                Log.e(TAG, e.getMessage()+"");
            }
        }

    }*/

//    /**
//     * 取这个导航是不是在首页中
//     *
//     * @return
//     */
//    private boolean HomePageEntrance.isHomeActivityInstance(getActivity()) {
//        if (getActivity() != null) {
//            String className = getActivity().getClass().getName();
//            return HomePageEntrance.HomeActivityClasses.contains(className);
//        }
//        return false;
//    }
    @Override
    protected RadioButtonX createRadioButtonItem(CatalogItem catalogItem) {
        RadioButtonX radioButtonX = super.createRadioButtonItem(catalogItem);
        radioButtonX.setText(catalogItem.getCatname());
        String frame = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getFrame();
        String type_select = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_selected_type();
        if (TextUtils.isEmpty(type_select)) {
            if (HomePageEntrance.isHomeActivityInstance(getActivity()) && (AppLayoutStyle.FrameStyle2.equals(frame))) {
                int textColor = 0;
                textColor = getResources().getColor(R.color.light_black_color);
                radioButtonX.setTextColor(textColor);
                radioButtonX.uncheckedTextColor = textColor;
                int color = Color.parseColor(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getColor());
                radioButtonX.checkedTextColor = color;
            } else {
                int textColor = 0;
                if (AppLayoutStyle.FrameStyle8.equals(frame)) {
                    //样式8 未选择中特定为白色效果
                    textColor = getResources().getColor(R.color.light_black_color);
                } else {
                    textColor = getResources().getColor(R.color.light_black_color);
                }
                radioButtonX.setTextColor(textColor);
                radioButtonX.uncheckedTextColor = textColor;
                int color = Color.parseColor(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getColor());
                radioButtonX.checkedTextColor = color;
            }
        } else {
            int textColor = 0;
            if (AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_unselected_type().equals("2")) {
                try {
                    textColor = Color.parseColor(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_unselected_color());
                } catch (Exception e) {
                    textColor = getResources().getColor(R.color.light_black_color);
                }
            } else {
                textColor = getResources().getColor(R.color.light_black_color);
            }
            radioButtonX.setTextColor(textColor);
            radioButtonX.uncheckedTextColor = textColor;
            int color = 0;
            if (AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_selected_type().equals("3")) {
                try {
                    color = Color.parseColor(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_selected_color());
                } catch (Exception e) {
                    color = textColor;
                }
            } else if (AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_selected_type().equals("2")) {
                color = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getMainColor();
            } else {
                color = textColor;
            }

            radioButtonX.checkedTextColor = color;
        }
     /*   if (AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_color() != 1) {
            radioButtonX.checkedTextColor = radioButtonX.uncheckedTextColor;
        }*/
        radioButtonX.setTag(RadioButtonX.TAG_TWO_NAVIGATION);
        return radioButtonX;
    }

   /* @Override
    protected void invalidateRadioButtonsPadding() {
        if (AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_underline() > 0)
            addItemBottomDrawable();
        super.invalidateRadioButtonsPadding();
    }

    protected void addItemBottomDrawable() {
        int margin = getResources().getDimensionPixelSize(R.dimen.appfactory_topcatalog_btnmargin);
        for (int i = 0; mCatalogGroupContainer != null && i < mCatalogGroupContainer.getChildCount(); i++) {
            RadioButtonX radioButtonX = (RadioButtonX) mCatalogGroupContainer.getChildAt(i);
            if(radioButtonX.getMeasuredWidth() ==0)
            {
                radioButtonX.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.AT_MOST);
            }
            tintAndAddBottom(radioButtonX, Utility.getTextViewWidth(radioButtonX) + margin);
        }
    }*/


    protected final void tintAndAddBottom(RadioButtonX radioButtonX, int width) {
        if (radioButtonX != null) {

            BitmapDrawable checkedDrawableDefault = (BitmapDrawable) getResources().getDrawable(R.drawable.msgcenter_checkdrawable);
            Bitmap bitmap = BitmapUtil.zoomBitmap(checkedDrawableDefault.getBitmap(), width, checkedDrawableDefault.getBitmap().getHeight());
            BitmapDrawable checkedDrawable = new BitmapDrawable(getResources(), bitmap);
            BitmapDrawable uncheckedDrawable = new BitmapDrawable(getResources(), bitmap);
            radioButtonX.checkedDrawable = checkedDrawable;
            radioButtonX.uncheckedDrawable = uncheckedDrawable;
            radioButtonX.updateEffDrawable();

            String frame = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getFrame();

            String underline = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_underline_color();

            if (null == underline || underline.equals("")) {
                if (AppLayoutStyle.FrameStyle2.equals(frame) || AppLayoutStyle.FrameStyle8.equals(frame)) {
                    radioButtonX.setTint(Color.WHITE, Color.TRANSPARENT);
                } else {
                    radioButtonX.setTint(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getMainColor(), Color.TRANSPARENT);
                }
            } else {
                radioButtonX.setTint(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getUnderLineColor(), Color.TRANSPARENT);
            }
        }
    }

    @Override
    protected RadioButtonCheckeChangedListener getRadioButtonCheckeChangedListener(
            RadioButtonX radioButtonX, int index) {
        return new RadioButtonCheckeChangedListenerX(radioButtonX, index);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.expand_container_taps) {
            if (!mEditColumnView.isShown()) {
                mEditColumnView.setVisibility(View.VISIBLE);
                mEditColumnView.setCurrShowData(mShowMenuData);
                mEditColumnView.currPage(lastSelectIndex);
                Animation hyperspaceJumpAnimation =
                        AnimationUtils.loadAnimation(getActivity(), R.anim.edit_nav_show);
                mEditColumnView.startAnimation(hyperspaceJumpAnimation);
            }
        }
    }

    boolean isLengthChangeLess = true;

    @Override
    public void onChange(List<CatalogItem> catalogItems) {


        if (catalogItems != null) {

            isLengthChangeLess = (catalogItems.size() <= mShowMenuData.size());
            mShowMenuData.clear();
            mShowMenuData.addAll(catalogItems);
            list.clear();
            for (int j = 0; j < mShowMenuData.size(); j++) {

                Fragment fragment = getViewContentFragment(mShowMenuData.get(j));
                if (fragment != null) {
                    list.add(fragment);
                }
            }
            List<IAdapterTitle> titleList = new ArrayList<>();
            titleList.addAll(mShowMenuData);
          //  AppThemeTabLayoutStyle.setTabLayoutStyle(getActivity(), mCatalogItemContainer, XTabLayout.MODE_SCROLLABLE);
            setCatalogItemContentList(getChildFragmentManager(), list);
            contentFragmentAdapter.titleList = titleList;
            mCatalogItemContainer.setViewPager(mContentViewPager);
            if (lastSelectIndex >= mShowMenuData.size()) {
                lastSelectIndex = 0;
                mContentViewPager.setCurrentItem(lastSelectIndex);
            } else {
                mContentViewPager.setCurrentItem(lastSelectIndex);
            }
            mCatalogItemContainer.setCurrentTab(lastSelectIndex);
        }
    }

    boolean isAdd = true;

    @Override
    public void onSelect(int ps) {
        lastSelectIndex = ps;
        try {
            mCatalogItemContainer.setCurrentTab(lastSelectIndex);
            mContentViewPager.setCurrentItem(lastSelectIndex);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected class RadioButtonCheckeChangedListenerX extends RadioButtonCheckeChangedListener {

        public RadioButtonCheckeChangedListenerX(RadioButtonX radioButtonX,
                                                 int index) {
            super(radioButtonX, index);
        }
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            super.onCheckedChanged(buttonView, isChecked);
            String currentTenantid = getResources().getString(R.string.tenantid);
            if (isChecked) {
                if (HomePageEntrance.isHomeActivityInstance(getActivity())) {
                    String frame = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getFrame();
                    if (AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_size() == 1) {
                        TextPaint tp = radioButtonX.getPaint();
                        tp.setFakeBoldText(true);
                        if (currentTenantid.equals(getResources().getString(R.string.tenant_jiangxi))) {
                            radioButtonX.setTextSize(18);
                        } else {
                            radioButtonX.setTextSize(TypedValue.COMPLEX_UNIT_PX, appfactory_topcatalog_checked_textsize);
                        }
                    }
                } else if (AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getNavigate_show_size() == 1) {
                    TextPaint tp = radioButtonX.getPaint();
                    tp.setFakeBoldText(true);
                    if (currentTenantid.equals(getResources().getString(R.string.tenant_jiangxi))) {
                        radioButtonX.setTextSize(18);
                    } else {
                        radioButtonX.setTextSize(TypedValue.COMPLEX_UNIT_PX, appfactory_topcatalog_checked_textsize);
                    }
                }
            } else {
                TextPaint tp = radioButtonX.getPaint();
                tp.setFakeBoldText(false);
                if (currentTenantid.equals(getResources().getString(R.string.tenant_jiangxi))) {
                    radioButtonX.setTextSize(18);
                } else {
                    radioButtonX.setTextSize(TypedValue.COMPLEX_UNIT_PX, appfactory_topcatalog_unchecked_textsize);
                }
            }
        }
    }

    /**
     * 设置左边那个按钮 在左菜单模式下可见 并且  顶部的容器背景色 与主色调一致
     */
    protected void setTopCatalogElementChilds() {

        String top_color = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getTop_color();
        if (HomePageEntrance.isHomeActivityInstance(getActivity())) {
            if (AppLayoutStyle.FrameStyle8.equals(getFrame()) || AppLayoutStyle.FrameStyle2.equals(getFrame())) {
                if (!TextUtils.isEmpty(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getHeader()) && skinHeaderBgImage != null) {
                    skinHeaderBgImage.setVisibility(View.VISIBLE);
                    skinHeaderBgImage.load(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getHeader());
                }
            }

            if (AppLayoutStyle.FrameStyle8.equals(getFrame())) {
                menuBtnTab.normalImg = getActivity().getResources().getDrawable(R.drawable.search);
                menuBtnTab.pressImg = getActivity().getResources().getDrawable(R.drawable.search);
                menuBtnTab.setVisibility(View.VISIBLE);
                menuBtnTab.updateEffDrawable();
                if (!TextUtils.isEmpty(top_color) && top_color.contains("#")) {
                    int parseColor = Color.parseColor(top_color);
                    menuBtnTab.setTint(parseColor, parseColor);
                }
                menuBtnContainer.setVisibility(View.VISIBLE);
                menuBtnContainer.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        gotoSearch();
                    }
                });
                int color = AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getMainColor();
                topContainer.setBackgroundColor(color);

                return;
            } else if (AppLayoutStyle.FrameStyle2.equals(getFrame())) {
                menuBtnContainer.setVisibility(View.VISIBLE);

                if (AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()) != null && TextUtils.isEmpty(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getColor()) == false) {
                    int color = Color.parseColor(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getColor());
                    topContainer.setBackgroundColor(color);
                }

                menuBtnContainer.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.setAction(GeneralBroadcast.OpenLeftMenu);
                        LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);
                    }
                });

                if (getIsMember()) {
                    menuBtnTab.normalImg = getActivity().getResources().getDrawable(R.drawable.person_normal);
                    menuBtnTab.pressImg = getActivity().getResources().getDrawable(R.drawable.person_press);
                    menuBtnTab.updateEffDrawable();
                    if (!TextUtils.isEmpty(top_color) && top_color.contains("#")) {
                        int parseColor = Color.parseColor(top_color);
                        menuBtnTab.setTint(parseColor, parseColor);
                    }

                    //取用户信息看要不要显示那个头像数据
                    {
                        UserInfo userInfo = UserInfo.getUserInfo(getActivity());
                        LoginBroadcast.sendLoginStatusBorad(userInfo, getActivity(), true);
                    }
                }
            }
        } else {
            int color = getResources().getColor(R.color.light_white_color);
            topContainer.setBackgroundColor(color);
        }
    }

    private void gotoSearch() {
        Intent intent = new Intent();
        intent.setClassName(getActivity(), "com.mediacloud.app.appfactory.activity.search.SearchActivity");
        getActivity().startActivity(intent);
    }

    protected void setCatalogItemContentList(FragmentManager manager, List<Fragment> list) {
        //如果子项只有一个table  那就把上面的tableNavigate隐藏掉
        if (list.size() == 1) {
            mRootView.findViewById(R.id.expand_container_taps).setVisibility(View.GONE);
            if (!AppLayoutStyle.FrameStyle9.equals(getFrame()) || !HomePageEntrance.isHomeActivityInstance(getActivity())) {
                mCatalogItemContainer.setVisibility(View.GONE);
                topContainer.setVisibility(View.GONE);
            }
        } else {
            mCatalogItemContainer.setVisibility(View.VISIBLE);
        }
        if (AppLayoutStyle.FrameStyle9.equals(getFrame()) && HomePageEntrance.isHomeActivityInstance(getActivity())) {
            topContainer.setBackgroundColor(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getMainColor());
            mRootView.findViewById(R.id.expand_container_taps).setVisibility(View.GONE);
            mRootView.findViewById(R.id.searchBtn).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    gotoSearch();
                }
            });
            mRootView.findViewById(R.id.userCenter).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    LoginUtils.intoProfile(getActivity(), LoginUtils.INVOKE_LOGIN);
                }
            });
        }
        super.setCatalogItemContentList(manager, (ArrayList) list);
        if (contentFragmentAdapter != null) {
            contentFragmentAdapter.needDestory = false;
        }
    }

    @Override
    public int getLayoutResID() {
       /* if(AppLayoutStyle.FrameStyle9.equals(getFrame())&&HomePageEntrance.isHomeActivityInstance(getActivity()))
            return R.layout.fragment_4activity_style9;*/
        return R.layout.aappfactory_fragment_with_catalogitems;
    }

    @Override
    public Fragment getViewContentFragment(CatalogItem catalogItem) {
        Fragment viewContentFragment = AppModuleUtils.getViewContentFragment(getActivity(), catalogItem);
        return viewContentFragment;
    }

    @Override
    public void userSignIn(IUserInfo userInfo) {
        if (!getIsMember())
            return;
        if (HomePageEntrance.isHomeActivityInstance(getActivity()) && AppLayoutStyle.FrameStyle2.equals(getFrame()) && !AppLayoutStyle.FrameStyle8.equals(getFrame())) {
            userIcon.setVisibility(View.VISIBLE);
            userIcon.setDefaultRes();
            userIcon.load(userInfo.getAvatar());
            menuBtnTab.setVisibility(View.GONE);
        }
    }

    @Override
    public void userSignOut(Intent intent) {
        if (!getIsMember())
            return;
        if (HomePageEntrance.isHomeActivityInstance(getActivity()) && AppLayoutStyle.FrameStyle2.equals(getFrame())) {
            userIcon.setVisibility(View.GONE);
            menuBtnTab.setVisibility(View.VISIBLE);
        }
    }

    String getFrame() {
        return AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getFrame();
    }

    boolean getIsMember() {
        return AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getIs_member() > 0;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (loginBroadcast != null) {
            getActivity().unregisterReceiver(loginBroadcast);
            loginBroadcast.userInfoChanged = null;
        }
    }

    @Override
    public void updateChildItemFragment(CatalogItem catalogItem, Fragment oldFragment, boolean sameId) {
        if (contentFragmentAdapter != null && contentFragmentAdapter.getList().contains(oldFragment)) {
            int index = contentFragmentAdapter.getList().indexOf(oldFragment);
            if (contentFragmentAdapter.titleList != null && index < contentFragmentAdapter.titleList.size()) {
                contentFragmentAdapter.titleList.set(index, catalogItem);
                if (index < mShowMenuData.size() && mShowMenuData.get(index) != null) {
                    mShowMenuData.get(index).setCatname(catalogItem.getCatname());
                    mEditColumnView.updateChannelItem(catalogItem, index);
                    mCatalogItemContainer.setCurrentTab(index, true);
                }
            }
            //如果id相同 那就不去替换了
            if (sameId || LBSChooseListener.getInstance().hadHandle)
                return;
            LBSChooseListener.getInstance().hadHandle = true;
            Fragment fragment = AppModuleUtils.getViewContentFragment(getActivity(), catalogItem);
            if (fragment != null)
                contentFragmentAdapter.setItem(index, fragment);
        } else if (oldFragment.getParentFragment() instanceof IHammerNavigate4LBS) {
            //如果id相同 那就不去替换了
            if (sameId || LBSChooseListener.getInstance().hadHandle)
                return;
            LBSChooseListener.getInstance().hadHandle = true;
            Fragment fragment = AppModuleUtils.getViewContentFragment(getActivity(), catalogItem);
            if (fragment != null)
                ((IHammerNavigate4LBS) oldFragment.getParentFragment()).replaceLBSFragment(catalogItem, oldFragment, fragment);
        }
    }


    @Override
    public void choosed() {
        isChoosed = true;
        if (contentFragmentAdapter != null && mContentViewPager != null && contentFragmentAdapter.getCount() > 0 && mContentViewPager.getCurrentItem() < contentFragmentAdapter.getCount()) {
            Fragment fragment = contentFragmentAdapter.getItem(mContentViewPager.getCurrentItem());
            if (fragment != null && fragment instanceof INaviateState) {
                ((INaviateState) fragment).choosed();
            }
        }
    }

    @Override
    public void unChosoed() {
        isChoosed = false;
        if (contentFragmentAdapter != null && mContentViewPager != null && contentFragmentAdapter.getCount() > 0 && mContentViewPager.getCurrentItem() < contentFragmentAdapter.getCount()) {
            Fragment fragment = contentFragmentAdapter.getItem(mContentViewPager.getCurrentItem());
            if (fragment != null && fragment instanceof INaviateState) {
                ((INaviateState) fragment).unChosoed();
            }
        }

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (contentFragmentAdapter == null || contentFragmentAdapter.getList() == null)
            return;
        for (int i = 0; i < contentFragmentAdapter.getList().size(); i++) {
            Fragment fragment = contentFragmentAdapter.getItem(i);
            if (fragment != null) {
                if (hidden)
                    fragment.onHiddenChanged(hidden);
                else {
                    if (i == mContentViewPager.getCurrentItem()) {
                        fragment.onHiddenChanged(hidden);
                    } else
                        fragment.onHiddenChanged(!hidden);
                }
            }
        }
    }
}